package com.tjsinfo.tjsoa.schedule.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.schedule.bo.IScheduleMainBo;
import com.tjsinfo.tjsoa.schedule.vo.ScheduleMain;
import com.tjsinfo.tjsoa.system.vo.User;


public class ScheduleWeekDayAction extends Action{
	  private IScheduleMainBo scheduleBo;
	    
		public IScheduleMainBo getScheduleBo() {
			return scheduleBo;
		}

		public void setScheduleBo(IScheduleMainBo scheduleBo) {
			this.scheduleBo = scheduleBo;
		}

		public ActionForward execute(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response) {
			Date date=new Date();
		
			ScheduleMain main = new ScheduleMain();
			String time = request.getParameter("time");
			
			HttpSession session = request.getSession();
			User user = (User) session.getAttribute("user");
		String[] timesplit = time.split("-");
		Integer year = Integer.valueOf(timesplit[0]);
		Integer month = Integer.valueOf(timesplit[1]);
		Integer day = Integer.valueOf(timesplit[2]);
			main.setScheduleYear(year);
			main.setScheduleMonth(month);
			main.setScheduleDay(day);
			main.setPeopleId(user.getUser_id());
			List<ScheduleMain> list = scheduleBo.findByDate(main);
			List<ScheduleMain> scheduleMainList = new ArrayList<ScheduleMain>();
			for (ScheduleMain scheduleMain : list) {
				String temp =  scheduleMain.getContent().replace("?", "");
				scheduleMain.setContent(temp);
				scheduleMainList.add(scheduleMain);
			}
			request.setAttribute("list", scheduleMainList);
			request.setAttribute("nowtime", year+"-"+month+"-"+day);
			return mapping.findForward("ok");
		}

}
